Array.prototype.myForEach = function (callBack: () => unknown) {
  if (typeof callBack !== 'function') throw new Error('传入回调函数')
  //   console.log(this);
  const _arr: any[] = [...this]
  for (let i = 0; i < _arr.length; i++) {
    const item = _arr[i]
    callBack(item, i, _arr)
  }
}

Array.prototype.myFilter = function (callBack: () => unknown) {
  //形参和实参
  if (typeof callBack !== 'function') throw new Error('传入回调函数')
  //   console.log(this);
  const result = []
  const _arr: any[] = [...this]
  for (let i = 0; i < _arr.length; i++) {
    const item = _arr[i]
    const bol = callBack(item)
    if (typeof bol === 'boolean') {
      bol && result.push(item)
    } else {
      throw new Error('返回布尔值')
    }
  }
  return result
}
